import axios from 'axios'

// -------------------------------学校-----------------------------
async function addGrade(gradeDetail, studentNumber) {
    const resp = await axios.post('/api/school/addGrade', gradeDetail, {
        params: {
            schoolWeID: localStorage.getItem('schoolWeID'),
            studentNumber: studentNumber
        }
    })
        .catch((e) => {
            window.$message.error(e.response.data.message)
        })
    return resp.data
}

async function deleteGrade(studentNumber, gradeName) {
    const resp = await axios.delete('/api/school/deleteGrade', {
        params: {
            studentNumber: studentNumber,
            gradeName: gradeName,
            schoolWeID: localStorage.getItem('schoolWeID')
        }
    }).catch((e) => {
        window.$message.error(e.response.data.message)
    })
    return resp.data
}

// -------------------------------学生-----------------------------
async function getGrades(studentNumber, schoolName, keyword) {
    const resp = await axios.get('/api/student/getGrade', {
        params: {
            schoolName: schoolName,
            studentNumber: studentNumber,
            keyword: keyword
        }
    }).catch((e) => {
        window.$message.error(e.response.data.message)
    })
    return resp.data
}

async function downloadGrade(studentNumber) {
    const resp = await axios.get('/api/student/downloadGrade', {
        params: {
            studentNumber: studentNumber
        }
    })
        .catch((e) => {
            window.$message.error(e.response.data.message)
        })
    return resp.data
}

export default {
    addGrade, deleteGrade, getGrades, downloadGrade
}